Quines
I was browsing reddit recently when I can across a link to a quine. Not just any ordinary quine, either – a polyglot quine. It works in three different languages: Haskell, OCaml, and Scheme.
For those who aren’t familiar with the term, a quine is a program that prints its own source code. There are a few fairly obvious caveats: it can’t read the code from the filesystem, it can’t take user input, empty programs don’t count. The term was coined by Douglas Hofstadter, who named it after logician Willard van Orman Quine. Interestingly, at the moment (and many moments before and after the current one – it’s a long book) I’m working my way through one of Hofstadter’s excellent books, Gödel, Escher, Bach, in which the word was coined and he goes into depth on the subject of quines. Unfortunately, I haven’t gotten to that point yet. When I do, I’ll be sure to mention it.
Quines are lots of fun to write, but more challenging than they may seem at first glance. I was inspired by this polyglot quine to write up a short one in Ruby. I started by trying the brute force method: creating a string containing the program.
s = "s =
About Me
Feed

4 Comments
More

